package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhentao.pojo.TOrder;
import com.zhentao.service.TOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhentao.util.Result;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    TOrderService tOrderService;
    @RequestMapping("/add")
    public Result add(@RequestBody TOrder tOrder){
        boolean save = tOrderService.save(tOrder);
        return save?Result.OK():Result.ERROR();
    }
    @RequestMapping("/find")
    public Result find(){
        List<TOrder> list=tOrderService.list();
        return list!=null?Result.OK(list):Result.ERROR();
    }
    @RequestMapping("/findByUserId")
    public Result findByUserId(Integer userId){
        QueryWrapper<TOrder> wrapper=new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<TOrder> list=tOrderService.list(wrapper);
        return list!=null?Result.OK(list):Result.ERROR();
    }
}
